#ifndef __BSP__LOG__H__
#define __BSP__LOG__H__
#include <stdio.h>
#include "usart.h"
typedef enum {
    LOG_DEBUG,
    LOG_INFO,
    LOG_WARN,
    LOG_ERROR
} LogLevel;

typedef int (*putc_t)(int);

/**
 * @brief 串口输出字符
 *
 * @param c
 * @return int
 */
static int uart_putc(int c) {
    return HAL_UART_Transmit(&huart1, (uint8_t*)&c, 1, 100) == HAL_OK ? c : EOF;
}
int eprintf(putc_t putcf, const char *fmt, ...);
/**
 * @brief 日志输出宏
 *
 */
#define BSP_LOG(level, fmt, ...) \
    do { \
        eprintf(uart_putc, "%s" fmt, \
            (level == LOG_DEBUG) ? "[DEBUG] " : \
            (level == LOG_INFO)  ? "[INFO] "  : \
            (level == LOG_WARN)  ? "[WARN] "  : "[ERROR]", \
            ##__VA_ARGS__); \
    } while (0)

#endif


